package com.csii.core.dict;

import com.csii.core.dict.handler.RedisDictGetHandler;
import com.csii.galaxy.studio.service.GalaxyStudioBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//@Component
public class DictService {

    @Autowired
    private GalaxyStudioBaseService galaxyStudioBaseService;

    @Autowired(required = false)
    private RedisTemplate redisTemplate;

    private RedisDictGetHandler redisDictGetHandler;

    @Value("${spring.name}")
    private String appName;

    @Value("${dict.isService:false}")
    private boolean isDictService;

    @PostConstruct
    private void buildRedisDictGetHandler(){
        redisDictGetHandler = new RedisDictGetHandler(galaxyStudioBaseService,redisTemplate,appName,isDictService);
    }

    @PreDestroy
    private void destroy(){
        redisDictGetHandler.destroy();
    }


    private String queryTableDictTextByKey(String table, String text, String code,String key){
        return galaxyStudioBaseService.queryTableDictTextByKey(table,text,code,key);
    }

    private String queryDictTextByKey(String code, String key){
        return redisDictGetHandler.queryDictTextByKey(code,key);
    }

}
